package main

import (
	"fmt"
	"math"
)

type Shape interface {
	Area() float64
	Perimeter() float64
}

type Circle struct {
	Radius float64
}

func (c Circle) Area() float64 {
	return math.Pi * c.Radius * c.Radius
}

func (c Circle) Perimeter() float64 {
	return 2 * math.Pi * c.Radius
}

// Empty Interface  泛化：使用空接口 interface{} 表示任意类型
func printValue(val interface{}) {
	fmt.Printf("Value = %d\t type=%T\n", val, val)
}

// 选择类型
func printType(val interface{}) {
	switch v := val.(type) {
	case int:
		fmt.Println("int", v)
	case string:
		fmt.Println("string", v)
	case float64:
		fmt.Println("float64", v)
	default:
		fmt.Println("unknown")
	}
}

// 空接口组合
type Reader interface {
	Read() string
}

type Writer interface {
	Write() string
}

type ReadWrite interface {
	Reader
	Writer
}

func main() {
	// 使用
	var s Shape = Circle{Radius: 5}
	fmt.Println(s.Area())
	fmt.Println(s.Perimeter())

	printValue(1)
	printType("golang")

}
